package com.coding.controller;

/**
 * @author Cynicism
 * @version 1.0
 * @project DyApp
 * @description
 * @date 2024/7/1 00:26:39
 */

import com.coding.utils.AliyunOSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/oss")
@CrossOrigin
public class FileUploadController {

    @Autowired
    private AliyunOSSUtil aliyunOSSUtil;

    @PostMapping("/upload")
    public String uploadFile(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return "File is empty";
        }
        String fileName = file.getOriginalFilename();
        String fileUrl = aliyunOSSUtil.uploadFile(file, fileName);
        return fileUrl != null ? fileUrl : "File upload failed";
    }
}
